package cn.tedu.demo.controller;

import cn.tedu.demo.pojo.vo.BannerListVO;
import cn.tedu.demo.service.IBannerService;
import cn.tedu.demo.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Slf4j
@Api(tags="轮播图管理模块")
@RequestMapping("/banner")
@RestController
public class BannerController {
    @Autowired
    IBannerService bannerService;

    @ApiOperation("添加轮播图")
    @ApiOperationSupport(order = 110)
    @PostMapping("/insert")
    public JsonResult<String> insertBanner(MultipartFile file) {
        log.debug("进入轮播图控制层，开始处理【添加轮播图】的请求");
        String fileName = bannerService.addNewBanner(file);
        return JsonResult.ok(fileName);
    }
    @ApiOperationSupport(order = 410)
    @ApiOperation("获取轮播图列表")
    @GetMapping("/get-list")
    public JsonResult<List<BannerListVO>> getBannerList(){
        log.debug("进入轮播图控制层，开始处理【获取轮播图列表】的请求");
        List<BannerListVO> listBanner = bannerService.getListBanner();
        return JsonResult.ok(listBanner);
    }


}
